<?php
namespace app\admin\logic;

use app\admin\model\MemberModel;
use Session;

class MemberLogic
{
	// 添加用户
	public function add_member($data)
	{
		// 状态值
        $data['status']      = empty($data['status']) ? -1 : $data['status'];

        // 插入
        $member = new MemberModel();
        if (!empty($data['user_id'])) {
        	
        	// 为空过滤密码，否则重置密码
        	if (empty($data['password'])) {
        		unset($data['password']);
        	}else{
		        // 密码设置
				$password         = md5($data['password']."sanw666");
				$data['password'] = $password;
        	}
        	
            $res  = $member->save_data($data);
        }else{
	        // 密码设置
			$password         = md5($data['password']."sanw666");  	
			$data['password'] = $password;
            
            $data['regist_ip']   = "127.0.0.1"; 
            $data['regist_time'] = date("Y-m-d H:i:s", time());
            $res  = $member->insert_data($data);
        }

        return $res;
	}

	// 获取用户信息
	public function get_member_info($user_id)
	{
		// 用户信息
        $member = new MemberModel();
        $info = $member::get($user_id);
        if (empty($info)) {
            return msg_error("数据不存在！");
        }

        return [
        	'info'  => $info,
        ];
	}

}